package edu.pku.sei.modeler.model.structure;
import org.w3c.dom.Element;

import edu.pku.sei.modeler.model.xml.XMLUtility;

/**
 * @author liangjie
 *
 */
public class MetaCompoundNode extends MetaNode {
	
	protected MetaNode sourceNode;
	protected MetaNode targetNode;
	public MetaNode getSourceNode() {
		return sourceNode;
	}
	public void setSourceNode(MetaNode sourceNode) {
		MetaNode oldSourceNode = this.sourceNode;
		this.sourceNode = sourceNode;
		this.firePropertyChange(StructurePackage.REFERENCENODE_SOURCENODE, oldSourceNode, sourceNode);
	}
	public MetaNode getTargetNode() {
		return targetNode;
	}
	public void setTargetNode(MetaNode targetNode) {
		MetaNode oldTargetNode = this.targetNode;
		this.targetNode = targetNode;
		this.firePropertyChange(StructurePackage.REFERENCENODE_TARGETNODE, oldTargetNode, targetNode);
	}
	
	public void serialize(Element root) {
		super.serialize(root);
		XMLUtility.xmlInstance.serializeNodeNotContain(root, StructurePackage.REFERENCENODE_SOURCENODE, sourceNode);
		XMLUtility.xmlInstance.serializeNodeNotContain(root, StructurePackage.REFERENCENODE_TARGETNODE, targetNode);
	}
	
	public void deSerialize(Element root) {
		super.deSerialize(root);
		sourceNode = (MetaNode)XMLUtility.xmlInstance.deSerializeNodeNotContain(root, StructurePackage.REFERENCENODE_SOURCENODE,this);
		targetNode = (MetaNode)XMLUtility.xmlInstance.deSerializeNodeNotContain(root, StructurePackage.REFERENCENODE_TARGETNODE,this);
	}
	
	public void dynamicSet(String featureID, Object value) {
		if(featureID.equals(StructurePackage.REFERENCENODE_SOURCENODE)) {
			sourceNode = (MetaNode)value;
		}
		else if(featureID.equals(StructurePackage.REFERENCENODE_TARGETNODE)) {
			targetNode = (MetaNode)value;
		}
		else {
			super.dynamicSet(featureID, value);
		}
	}
}
